/*
 * Copyright (C) 2011, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.controller;

/**
 *
 * @author Laurent WOUTERS
 */
public class Image extends Element {
    private xowl.gmi.view.diagram.Image widget;
    
    public Image(Controller controller, Element parent, xowl.gmi.model.cvssl.Image def) {
        super(controller, parent);
        String source = getValueString(def.getSource(), getObserverSource());
        javax.swing.ImageIcon icon = null;
        if (source != null) icon = xowl.gmi.view.IconProvider.getExternal(source);
        this.widget = new xowl.gmi.view.diagram.Image(icon);
    }
    
    private xowl.interpreter.adapter.DataPropertyObserver getObserverSource() {
        return new xowl.interpreter.adapter.DataPropertyObserver() {
            @Override public void onAdd(Object elem) {
                widget.setIcon(xowl.gmi.view.IconProvider.getExternal((String)elem));
                controller.onDiagramUpdated();
            }
            @Override public void onRemove(Object elem) { }
        };
    }
    
    @Override public xowl.gmi.view.diagram.Widget getWidget() { return widget; }
    
    @Override protected int getContainedASTCount() { return 0; }
    @Override protected int getLeftSiblingsASTCount(Element divider) { return 0; }
    @Override protected boolean insertAST(xowl.gmi.model.ast.ASTNode node) { return false; }
    @Override protected ASTRemovalStatus removeAST(xowl.gmi.model.ast.ASTNode node) { return ASTRemovalStatus.NodeNotFound; }
    
    @Override public void saveTo(xowl.gmi.model.Diagram diagram) { }
    @Override public void decommission() { }
}
